<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:base="http://java.sun.com/jsf/composite/base">
    <h:head>
        <title>Facelet Title</title>
    </h:head>
    <h:body>

        <h1>基础框架之 内循环表 ---> 无极限菜单树</h1>
        <h:form>
            <h:inputText value="#{categoryController.category.name}"/>
            <h:inputText value="#{categoryController.category.url}"/>
            <h:selectOneMenu value="#{categoryController.category.parentCategory}" converter="#{categoryController.converter}">
                <f:selectItem itemValue="" itemLabel="first"/>
                <f:selectItems value="#{categoryController.all}" var="category" itemValue="#{category}" itemLabel="#{category.name}"/>
            </h:selectOneMenu>
            <h:commandButton 
                value="create"
                action="#{categoryController.createCategory}"/>
        </h:form>
        <hr/>
        <h:form>
            <hr/>
            <p:menubar binding="#{categoryController.menubar}"/>
            <hr/>
        </h:form>
        <h:form>
            <p:contextMenu for="tree">
                <p:menuitem value="增加同级" onclick="bbbb.show();"/>
                <p:menuitem value="增加子级" onclick="temp.show();"/>
                <p:menuitem value="删除" actionListener="#{categoryController.removeNode}" update="tree"/>
            </p:contextMenu>
            <p:tree value="#{categoryController.tree}" var="node" id="tree" 
                    selectionMode="single"                    
                    selection="#{categoryController.selectNode}"
                    animate="true">  
                <p:treeNode id="treeNode">  
                    <h:outputText value="#{node.name}" id="lblNode"/>  
                </p:treeNode>  
            </p:tree> 
            <p:dialog widgetVar="temp">

                <h:inputText value="#{categoryController.category.name}"/>
                <p:commandButton value="create"
                                 update="tree"
                                 oncomplete="temp.hide();"
                                 action="#{categoryController.addNode}"/>
            </p:dialog>

            <p:dialog widgetVar="bbbb">
                <h:inputText value="#{categoryController.category.name}"/>
                <p:commandButton value="create"
                                 update="tree"
                                 oncomplete="bbbb.hide();"
                                 action="#{categoryController.addParentNode}"/>
            </p:dialog>
        </h:form>
        <hr/>
        <hr/>
        <base:treeNode/>
    </h:body>
</html>

